
/*
 * sndpipe: A UNIX pipes-based audio stream processor toolkit.
 * Copyright (C) 2011  Bradley Worley
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to:
 *
 *   Free Software Foundation, Inc.
 *   51 Franklin Street, Fifth Floor
 *   Boston, MA  02110-1301, USA.
 */

/* ensure once-only inclusion. */
#ifndef __SNDPIPE_GLOBAL__
#define __SNDPIPE_GLOBAL__

/* define status codes for functions. */
#define SP_OK      0
#define SP_FAIL    1
#define SP_UNKNOWN 0

/* define boolean values. */
#define SP_TRUE  1
#define SP_FALSE 0

/* define available main function strings. */
#define SP_FUNC_GEN  "GEN"
#define SP_FUNC_CAP  "CAP"
#define SP_FUNC_OUT  "OUT"
#define SP_FUNC_DEL  "DEL"
#define SP_FUNC_ADD  "ADD"
#define SP_FUNC_SUB  "SUB"
#define SP_FUNC_MUL  "MUL"
#define SP_FUNC_DIV  "DIV"
#define SP_FUNC_FIL  "FIL"
#define SP_FUNC_BLK  "BLK"
#define SP_FUNC_TRG  "TRG"
#define SP_FUNC_WIN  "WIN"
#define SP_FUNC_FFT  "FFT"
#define SP_FUNC_TXT  "TXT"
#define SP_FUNC_PAS  "PAS"
#define SP_FUNC_DIS  "DIS"

/* define an error-checking utility function. */
#define ASSERT(a) if (!(a)) { \
    fprintf (stderr, "%s:%u: !(%s)\n", __FILE__, __LINE__, #a); \
    fflush (stderr); \
    exit (SP_FAIL); \
  }

/* define relations between degrees and radians. */
#define DEG(a) (180.0 * (a) / M_PI)
#define RAD(a) (M_PI * (a) / 180.0)

/* define values for the real and imaginary indices of complex arrays. */
#define RE 0
#define IM 1

/* define a swap function, mainly used in the fft code. */
#define SWAP(a,b) temp = (a); (a) = (b); (b) = temp;

/* define wrappers around the printf-style functions. */
#define failf(...) failf_fn (SP_TRUE, __FILE__, __LINE__, __VA_ARGS__)
#define warnf(...) failf_fn (SP_FALSE, __FILE__, __LINE__, __VA_ARGS__)

/* define the help message string. */
#define SP_HELP_MESSAGE "\
 sndpipe: A tool for audio manipulation and measurement using UNIX pipes.\n\
 Copyright (C) 2011 Bradley Worley. Released under the GNU GPL 2.0.\n\
\n\
 Usages:\n\
   sndpipe -h,--help\n\
   sndpipe -x,--function FUNC [function-arguments]\n\
\n\
 The architecture of sndpipe is such that each instance of the program is\n\
 performing a small modification to a stream of audio, sent from one\n\
 program to the next via UNIX pipes. The small modifications that sndpipe\n\
 supports are called 'functions'. Some functions are standalone, such as\n\
 'CAP' and 'GEN', and can run without an input stream, but will add new\n\
 channels to existing streams if asked to do so. Others, like 'BLK' and\n\
 'TRG', simply add placeholder channels for use later. Others yet, like\n\
 'WIN' and 'FFT', may modify time-series data in-place or even completely\n\
 replace it with frequency-domain information, adding no new channels.\n\
\n\
 To see more information about specific functions, run sndpipe with the\n\
 --help and --function flags both set.\n\
\n\
"

/* define the help message header for function-specific help. */
#define SP_HELP_HEADER "\
 sndpipe: A tool for audio manipulation and measurement using UNIX pipes.\n\
 Copyright (C) 2011 Bradley Worley. Released under the GNU GPL 2.0.\n\
"

/* define the function-specific help message struct. */
struct function_help {
  /* the function name and its help string. */
  char *func;
  char *help;
};

/* begin function definitions here. */

void failf_fn (const int do_exit, const char *f, const unsigned int l,
               const char *format, ...)
  __attribute__ ((format (printf, 4, 5)));

void helpf (const char *func);

#endif /* __SNDPIPE_GLOBAL__ */

